<!doctype html>
<html>
	<head>
		<title>Counter</title>
		<link rel="shortcut icon" href="favicon.png">
		<style>
		* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
		body { height: 100vh; display: flex; align-items: center; justify-content: center; background-color: #f1c40f; font-family: 'Helvetika Neue', Arial, sans-serif; font-size: 28px; }
		.counter-container { display: flex; flex-direction: column; align-items: center; }
		.counter { text-transform: uppercase; color: #fff; font-weight: bold; font-size: 3rem; }
		.btn-row { display: flex; align-items: center; margin: 1rem; }
		.btn { cursor: pointer; min-width: 4em; padding: 1em; border-radius: 5px; text-align: center; margin: 0 1rem; box-shadow: 0 6px #8b5e00; color: white; background-color: #E4B702; position: relative; font-weight: bold; }
		.btn:hover { box-shadow: 0 4px #8b5e00; top: 2px; }
		.btn:active{ box-shadow: 0 1px #8b5e00; top: 5px; }
		</style>
	</head>
	<body onload=start()>
		<!-- UI layout -->
		<div class="counter-container">
			<div class="counter"></div>
			<div class="btn-row">
				<div class="btn btn-incr">+1</div>
				<div class="btn btn-decr">-1</div>
			</div>
		</div>

		<!-- Connect UI actions to Go functions -->
		<script>
			const counter = document.querySelector('.counter');
			const btnIncr = document.querySelector('.btn-incr');
			const btnDecr = document.querySelector('.btn-decr');

			// We use async/await because Go functions are asynchronous
			const render = async () => {
				counter.innerText = `Count: ${await window.counterValue()}`;
			};

			btnIncr.addEventListener('click', async () => {
				await counterAdd(1); // Call Go function
				render();
			});

			btnDecr.addEventListener('click', async () => {
				await counterAdd(-1); // Call Go function
				render();
			});

			render();
		</script>
	</body>
</html>
